<template>
  <div class="app-container" v-enter-helper="getList">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row class="mb-4">
          <el-button type="primary" @click="handleExport">导出</el-button>
        </el-row>
        <el-row>
          <el-form
            :inline="true"
            :model="listQuery"
            ref="dataList2"
            class="demo-form-inline"
          >
            <el-form-item label="">
              <el-input
                type="text"
                clearable
                v-model.number="listQuery.user_code"
                placeholder="用户编号"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input
                type="text"
                clearable
                v-model="listQuery.nickname"
                placeholder="用户昵称"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input
                type="text"
                clearable
                v-model="listQuery.mobile"
                placeholder="用户手机号"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input
                type="text"
                clearable
                v-model="listQuery.remark"
                placeholder="封禁理由"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-select
                filterable
                v-model="listQuery.admin_id"
                placeholder="请选择操作人"
                clearable
              >
                <el-option
                  v-for="item in adminOptions"
                  :key="item.admin_id"
                  :label="item.admin_name"
                  :value="item.admin_id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="date"
                clearable
                type="datetimerange"
                value-format="timestamp"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="handleChangeData"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="searchSubmit">查询</el-button>
              <el-button type="primary" @click="resetSubmit">重置</el-button>
            </el-form-item>
          </el-form>
        </el-row>
      </div>
      <div class="item">
        <el-table
          v-loading="listLoading"
          ref="dataList"
          :data="menuList"
          style="width:100%;margin-bottom: 20px;"
          row-key="id"
          border
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        >
          <!-- <el-table-column type="selection"></el-table-column> -->
          <el-table-column prop="id" label="序号"></el-table-column>
          <el-table-column prop="user_code" label="用户编号"></el-table-column>
          <el-table-column prop="nickname" label="昵称"></el-table-column>
          <el-table-column prop="mobile" label="用户手机号"></el-table-column>
          <el-table-column
            prop="add_time"
            label="封禁开始时间"
          ></el-table-column>
          <el-table-column
            prop="seal_time"
            label="封禁结束时间"
          ></el-table-column>
          <el-table-column prop="remark" label="封禁理由"></el-table-column>
          <el-table-column prop="admin_name" label="操作人"> </el-table-column>
          <el-table-column label="操作" width="100px">
            <template slot-scope="scope">
              <el-button
                type="danger"
                size="mini"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                plain
                >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <cus-pagination
          :total="total"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.perPage"
          @pagination="getList"
        />
      </div>
    </el-card>
    <!-- 删除弹框 -->
    <el-dialog
      title="确定删除吗?"
      :visible.sync="deleteDialogVisible"
      width="435px"
    >
      <span style=""
        ><em style="font-style:normal;color:red">删除后不可恢复</em
        >，你还要继续吗？</span
      >
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmDelete">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  listData,
  deleteData,
  getExport,
  getAdminList
} from "@/api/member/userSeal";

export default {
  data() {
    return {
      confirmBtn: false,
      adminOptions: [],

      deleteDialogVisible: false,
      listLoading: false,
      menuList: [],
      total: 10,
      date: null,
      listQuery: {
        page: 1,
        perPage: 10,
        user_code: undefined,
        admin_id: undefined,
        mobile: undefined,
        nickname: undefined,
        remark: undefined,
        start_time: undefined,
        end_time: undefined
      },
      dataIds: ""
    };
  },
  async created() {
    await this.handleGetAdminList();
    await this.getList();
  },
  methods: {
    async getList() {
      const res = await listData(this.listQuery);
      this.menuList = res.data.list;
      this.total = res.data.meta.total;
      this.confirmBtn = false;
    },
    handleGetAdminList() {
      getAdminList().then(res => {
        this.adminOptions = res.data.list;
      });
    },
    handleChangeData(value) {
      if (!value) {
        this.listQuery.start_time = undefined;
        this.listQuery.end_time = undefined;
      } else if (value && value.length === 2) {
        this.listQuery.start_time = value[0] / 1000;
        this.listQuery.end_time = value[1] / 1000;
      }
    },
    // 查询
    searchSubmit() {
      this.listQuery.page = 1;
      this.getList();
    },
    // 重置
    resetSubmit() {
      this.date = null;
      this.listQuery = {
        page: 1,
        perPage: 10,
        user_code: undefined,
        admin_id: undefined,
        mobile: undefined,
        nickname: undefined,
        remark: undefined,
        start_time: undefined,
        end_time: undefined
      };
      this.getList();
    },
    // 点击单个删除
    handleDelete(row) {
      this.dataIds = { ids: row.id.toString() };
      this.deleteDialogVisible = true;
    },
    // 确定删除
    confirmDelete() {
      if (this.confirmBtn) return;
      this.confirmBtn = true;
      // this.dataIds)
      this.deleteDialogVisible = false;
      deleteData(this.dataIds).then(response => {
        if (response.code === 200) {
          this.getList();
          this.deleteDialogVisible = false;
          this.$notify({
            type: "success",
            message: "操作成功",
            position: "bottom-right",
            showClose: false,
            duration: 3000
          });
        } else {
          this.confirmBtn = false;
        }
      });
    },

    handleExport() {
      getExport(this.listQuery).then(res => {
        if (res.code === 200) {
          window.location.href = res.data.uri;
        }
      });
    }
  }
};
</script>

<style scoped>
[v-cloak] {
  display: none;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}

.demo-form-inline {
  /* float: right; */
}

/deep/ .el-card__header {
  padding-bottom: 0;
}
</style>
